(function($, doc) {
	$.init();
	var userinfo = app.getState();
	var uid = userinfo.user_id;
	var myWallet = ethscan.getWallet('eth');
	var qrcode = new QRCode('qr', {
		text: myWallet.address,
		width: 250,
		height: 250,
		colorDark: '#000000',
		colorLight: '#ffffff',
		correctLevel: QRCode.CorrectLevel.H
	});
	doc.getElementById('address').innerHTML = myWallet.address;
	var clipboard = new Clipboard('.mui-btn-block', {
		// 通过target指定要复印的节点
		text: function() {
			return document.querySelector('#address').innerText;
		}
	});
	clipboard.on('success', function(e) {
		console.log(JSON.stringify(e));
		mui.toast("已复制钱包地址");
	});
	var baseImgFile = function(uid, base64, quality, callback) {
		quality = quality || 10;
		callback = callback || $.noop;
		var bitmap = new plus.nativeObj.Bitmap();
		// 从本地加载Bitmap图片 
		bitmap.loadBase64Data(base64, function() {
			//    console.log('加载图片成功'); 
			bitmap.save("_doc/" + uid + ".jpg", {
				overwrite: true,
				quality: quality
			}, function(i) {
				callback(i);
				//    console.log('保存图片成功：'+JSON.stringify(i)); 
			}, function(e) {
				console.log('保存图片失败：' + JSON.stringify(e));
			});
		}, function(e) {
			console.log('加载图片失败：' + JSON.stringify(e));
		});
	}
	mui.plusReady(function() {
		//点击保存二维码
		document.getElementById('save_qrcode').addEventListener('tap', function() {
			var path = document.querySelector('#qr img').src;
			//转成jpg格式存到本地
			baseImgFile('sk_qrcode_' + uid, path, 100, function(i) {
				//alert(JSON.stringify(i)); 
				console.log(JSON.stringify(i));
			});

			var new_path = "_doc/" + 'sk_qrcode_' + uid + ".jpg";
			plus.gallery.save(new_path, function() {
				mui.toast('保存图片成功！');
			}, function() {
				mui.toast('保存失败');
			});
		}, false);
		/*
		document.getElementById('rollin_record').addEventListener('tap', function() {
			//打开转入记录页
			mui.openWindow({
				id: 'rollin_record.html',
				url: 'rollin_record.html',
				show: {
					autoShow: false
				},
				waiting: {
					autoShow: true, //自动显示等待框，默认为true
					title: '正在加载...' //等待对话框上显示的提示内容
				}
			});
		})*/

	})
}(mui, document));